package Extends.CUICompents.CCtrls
{
	import flash.events.EventDispatcher;
	
	import Extends.CEvent.CustomEvent;
	
	public class CMRadioButtonGroup extends EventDispatcher
	{
		static public const RADIO_GROP_ITEM_SELECTED:String = "RADIO_GROP_ITEM_SELECTED";
		protected var ms_radioArr:Array = new Array();
		protected var ms_curRadio:CMRadioButton = null;
		public function CMRadioButtonGroup()
		{
			super();
		}
		
		public function set group(radio:CMRadioButton):void
		{
			if(ms_radioArr.indexOf(radio) == -1)
			{
				ms_radioArr.push(radio);
				radio.addEventListener(CMRadioButton.RADIO_BUTTON_ITEM_CLICK,onSelected);
			}
		}
		protected function onSelected(event:CustomEvent):void
		{
			var radio:CMRadioButton = event.target as CMRadioButton;
			ms_curRadio = radio;
			for each(var r:CMRadioButton in ms_radioArr)
			{
				if(r.selected && r != radio)
				{
					r.selected = false;
				}
			}
			var evt:CustomEvent = new CustomEvent(CMRadioButtonGroup.RADIO_GROP_ITEM_SELECTED);
			evt.event_data = radio;
			this.dispatchEvent(evt);
		}
		
		public function get selectedValue():Object
		{
			if(ms_curRadio)
			{
				return ms_curRadio.value;
			}
			return null;
		}
	}
}